#!/usr/bin/env bash

#通过/usr/bin/env 相比#!/usr/bin/bash，它会根据你的环境寻找并运行默认的版本，提供灵活性

IID=$(docker images | grep 'wlj/my-admin' | awk '{print $1}')
if [ ! $IID ]; then
  echo "'my-admin' image not exist,building... "
  docker build --build-arg APP_ENV="production" --build-arg PORT=9002 -t wlj/my-admin .
else
  echo "'my-admin' image existed "
fi

#查询这个容器, 并停止 移除它
CID=$(docker ps -a | grep 'my-admin' | awk '{print $1}')
if [ ! $CID ]; then
  echo "'my-admin' container not exist "
else
  echo "'my-admin' container existed,rm it... "
  docker stop $CID
  docker rm $CID
fi
#执行新起一个容器,在这之前确保redis服务已运行或者通过docker-compse.yml一步启动到位
docker run -d -p 9001:9002 --name my-admin -e TZ=Asia/Shanghai  wlj/my-admin